<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    {include file="public/static" /}
</head>
<body>

<div class="x-nav">
    <span class="layui-breadcrumb">
        {include file="public/navLow" /}

        {notempty name="parent"}
            {volist name="parent" id="vo"}
                <a href="{:url('Auth/authRuleList',['pid'=>$vo.ar_id])}"><cite>{$vo.ar_name}</cite></a>
            {/volist}
        {/notempty}
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <span class="layui-badge">注意：此页面需要技术人员操作</span>

                    <form class="layui-form layui-col-space5" >
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="name" placeholder="方法名称" autocomplete="off" class="layui-input" value="{$Request.param.name}"/>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="method" placeholder="方法地址" autocomplete="off" class="layui-input" value="{$Request.param.method}" />
                        </div>
                        <div class="layui-inline layui-show-xs-block" style="width: 100px;">
                            <select name="status" id="status" >
                                <option value="">选择状态</option>
                                <option value="1" {eq name="Request.param.status" value="1"} selected {/eq}>启用</option>
                                <option value="0" {eq name="Request.param.status" value="0"} selected {/eq}>禁用</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>搜索</button>
                            <a href="{:url('Auth/authRuleList')}">
                                <button type="button" class="layui-btn"><i class="layui-icon">&#xe639;</i>清空</button>
                            </a>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    {eq name="check.AuthauthRuleAdd" value="1"}
                        {empty name="Request.param.pid"}
                            <button class="layui-btn" onclick="common.openWindow('新增权限','{:url('Auth/authRuleAdd')}','500','380')">
                                <i class="layui-icon">&#xe654;</i>新增权限
                            </button>
                        {else/}
                            <button class="layui-btn" onclick="common.openWindow('新增下级','{:url('Auth/authRuleAdd',['pid'=>$Request.param.pid])}','500','380')">
                                <i class="layui-icon">&#xe654;</i>新增下级
                            </button>
                        {/empty}
                    {/eq}
                    {eq name="check.AuthauthRuleDelAll" value="1"}
                        <button class="layui-btn layui-btn-danger" onclick="dataDelAll()">
                            <i class="layui-icon">&#xe640;</i>批量删除
                        </button>
                    {/eq}
                    {eq name="check.AuthauthRuleRedis" value="1"}
                        <button class="layui-btn layui-btn-normal" onclick="dataRedis()">
                            <i class="layui-icon">&#xe666;</i>更新缓存
                        </button>
                    {/eq}
                </div>
                <div class="layui-card-body layui-table-body">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>
                                <input type="checkbox" lay-filter="checkbox" name="id" value="" lay-skin="primary">
                            </th>
                            <th>权限id</th>
                            <th>方法名称</th>
                            <th>方法URL</th>
<!--                            <th>前台/后台</th>-->
                            <th>状态</th>
                            <th>操作</th>
                        </thead>
                        <tbody>
                            {volist name="info" id="vo"}
                                <tr>
                                    <td>
                                        <input type="checkbox" name="id[]" value="{$vo.ar_id}" lay-skin="primary">
                                    </td>
                                    <td>{$vo.ar_id}</td>
                                    <td>{$vo.ar_name}</td>
                                    <td>{$vo.ar_method}</td>
<!--                                    <td>-->
<!--                                        {eq name="vo.ar_beforeAfter" value="1"}-->
<!--                                            <span class="layui-btn layui-btn-xs layui-btn-mini">后台</span>-->
<!--                                        {else/}-->
<!--                                            <span class="layui-btn layui-btn-danger layui-btn-mini">前台</span>-->
<!--                                        {/eq}-->
<!--                                    </td>-->
                                    <td>
                                        {eq name="vo.ar_status" value="1"}
                                            <span class="layui-badge layui-bg-green">启用</span>
                                        {else/}
                                            <span class="layui-badge">禁用</span>
                                        {/eq}
                                    </td>
                                    <td class="td-manage">
                                        <a href="{:url('Auth/authRuleList',['pid'=>$vo.ar_id])}">
                                            <i class="layui-icon">&#xe705;</i>查看下级
                                        </a>
                                        {eq name="check.AuthauthRuleEdit" value="1"}
                                            <a href="javascript:;" onclick="common.openWindow('编辑权限','{:url('Auth/authRuleEdit',['id'=>$vo.ar_id])}','500','380')" >
                                                <i class="layui-icon">&#xe642;</i>编辑
                                            </a>
                                        {/eq}
                                        {eq name="check.AuthauthRuleDel" value="1"}
                                            <a onclick="dataDel(this,'{$vo.ar_id}')" href="javascript:;" >
                                                <i class="layui-icon">&#xe640;</i>删除
                                            </a>
                                        {/eq}
                                    </td>
                                </tr>
                            {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        {$info|raw}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    /*全选*/
    common.selectCheckbox('checkbox','id[]');
    /*缓存更新*/
    function dataRedis(){
        layer.confirm('确认要更新权限缓存吗？',function(){
            var index = layer.load();
            //发异步删除数据
            $.ajax({
                type:"post",
                url:"{:url('Auth/authRuleRedis')}",
                dataType:'json',
                success:function (data) {
                    if(data.status === 1){
                        layer.msg(data.info, {icon: 6,time:1500});
                    }else{
                        layer.msg(data.info, {icon: 5,time:1500});
                    }
                    layer.close(index);
                },
                error:function (data) {
                    console.log(data);
                    layer.msg("不好意思，出现了一点问题", {icon: 5});
                }
            });
        });
    }
    /*删除*/
    function dataDel(obj,id){
        layer.confirm('确认要删除这条数据吗？',function(){
            var index = layer.load();
            //发异步删除数据
            $.ajax({
               type:"post",
               url:"{:url('Auth/authRuleDel')}",
               data:{id:id},
               dataType:'json',
               success:function (data) {
                   if(data.status === 1){
                       $(obj).parents("tr").remove();
                       layer.msg(data.info, {icon: 6,time:1500});
                   }else{
                       layer.msg(data.info, {icon: 5,time:1500});
                   }
                   layer.close(index);

               },
               error:function (data) {
                   console.log(data);
                   layer.msg("不好意思，出现了一点问题", {icon: 5});
               }
            });
        });
    }
    /*批量删除*/
    function dataDelAll() {
        //获取checkbox值
        var ids = common.getCheckboxVal();
        if(ids.length < 1){
            layer.msg('请选择需要操作的数据！',{time:1500, icon:5});
            return false;
        }
        layer.confirm('确认要删除选中的数据吗？',function(){
            var index = layer.load();
            $.ajax({
                type: 'POST',
                url: "{:url('Auth/authRuleDelAll')}",
                data: {ids:ids},
                dataType:'json',
                success:function(data){
                    if(data.status === 1){
                        layer.msg(data.info,{time:1500, icon:6},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data.info,{time:1500, icon:5});
                    }
                    layer.close(index);

                },
                error:function(){
                    console.log(data.msg);
                    layer.msg("不好意思，出现了一点问题", {icon: 5});
                }
            });
        });
    }
</script>
</html>